package com.mail;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by luojie on 2018/5/30.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:application-mail.xml"})
public class SingleMailSend {

    @Autowired
    private MailSender mailSender;

    @Autowired
    private SimpleMailMessage simpleMailMessage;

    @Test
    public void test(){
        SimpleMailMessage simpleMailMessage1 = new SimpleMailMessage(this.simpleMailMessage); //SimpleMailMessage只能用来发送text格式的邮件
        simpleMailMessage1.setTo("2107279101@qq.com");
        simpleMailMessage1.setText("测试内容");
        try{
            this.mailSender.send(simpleMailMessage1);
            System.out.println("邮件发送成功...");
        }
        catch (MailException e){
            System.out.println(e.getMessage());
        }
    }
}
